{include file='_header'}
<script type="text/javascript" src="__STATIC__/js/lib/moment.js"></script>
<link rel="stylesheet" href="__STATIC__/components/datetimepicker/jquery.datetimepicker.css">
<link rel="stylesheet" href="__STATIC__/components/daterangepicker/daterangepicker.css">
<div class="page-header">
    当前位置：<span class="text-primary">{if !empty($item['id'])}编辑{else}添加{/if}商品 <small>{if !empty($item['id'])}修改【{$item['title']}】 {/if} </small></span>
</div>
<div class="page-content">
    <div class="page-sub-toolbar">
        <span class=''>
            <a class="btn btn-primary btn-sm" href="{:url('admin/treasure/goodsadd')}">添加新商品</a>
        </span>
    </div>
<form id="dataform" action="" method="post" class="form-horizontal form-validate">
    <input type='hidden' id='id' name='id' value="{$item['id']}" />
    <div class="form-group">
        <label class="col-lg control-label">商品排序</label>
        <div class="col-xs-12 col-sm-8">
            <input style="width: 50%;" type="text" name="goods[sort]" class="form-control" value="{$item['sort']}" />
            (数字越大排序越靠前)
        </div>
    </div>
    <div class="form-group">
        <label class="col-lg control-label">商品标题</label>
        <div class="col-xs-12 col-sm-8">
            <input type="text" name="goods[title]" class="form-control" value="{$item['title']}" />
        </div>
    </div>
    <div class="form-group">
        <label class="col-lg control-label"><span style='color:red'>*</span>商品分类</label>
        <div class="col-sm-8 col-xs-12">
            <select name="goods[category]" class="form-control">
            {foreach name='category' item='row'}
                <option value="{$row['id']}" {if $item['categoryid']==$row['id']}selected="selected"{/if}>{$row['name']}</option>
            {/foreach}}
            </select>
        </div>
    </div>
    <div class="form-group">
        <label class="col-lg control-label must">商品图片</label>
        <div class="col-sm-8 col-xs-12 gimgs">
            {:tpl_form_field_multi_image2('thumbs',$piclist)}
            <span class="help-block image-block" style="display: block;">第一张为缩略图，建议为正方型图片，其他为详情页面图片，尺寸建议宽度为640，并保持图片大小一致</span>
            <span class="help-block">您可以拖动图片改变其显示顺序 </span>
        </div>
    </div>
    <div class="form-group">
        <label class="col-lg control-label">商品价格</label>
        <div class="col-xs-12 col-sm-8">
            <div class="input-group">
                <input type="text" name="goods[price]" class="form-control" value="{$item['price']}" {if !empty($id)} disabled="disabled" {/if}>
                <span class="input-group-addon">元</span>
            </div>
        </div>
    </div>
    <div class="form-group">
        <label class="col-lg control-label">状态</label>
        <div class="col-xs-12 col-sm-8">
            <label class="radio radio-inline">
                <input type="radio" name="goods[status]" value="0" {if intval($item['status']) != 1}checked="checked"{/if}> 下架
            </label>
            <label class="radio radio-inline">
                <input type="radio" name="goods[status]" value="1" {if intval($item['status']) == 1}checked="checked"{/if}> 上架
            </label>
        </div>
    </div>
    <div class="form-group">
        <label class="col-lg control-label">商品详情</label>
        <div class="col-xs-12 col-sm-8">
            {:tpl_ueditor('goods[content]', $item['content']);}
        </div>
    </div>
    <div class="form-group-title">夺宝设置</div>
    <div class="form-group">
        <label class="col-lg control-label">几元专区</label>
        <div class="col-xs-12 col-sm-8">
            <input style="width: 50%;" type="number" name="goods[init_money]" class="form-control" value="{$item['init_money']}" />
            {if $item['next_init_money'] == 0}(下期专区价格不变){else}(本期结束，下一期专区价格修改为{$item['next_init_money']}元专区){/if}
        </div>
    </div>
    <div class="form-group">
        <label class="col-lg control-label">最大购买数</label>
        <div class="col-xs-12 col-sm-8">
            <input style="width: 50%;" type="text" name="goods[maxnum]" class="form-control" value="{$item['maxnum']}" />
            (0为任意购买数量，默认0)
        </div>
    </div>
    
    <div class="form-group">
        <label class="col-lg control-label">是否发送开奖通知</label>
        <div class="col-xs-12 col-sm-8" style="width: 70%;">
            <label class="radio radio-inline">
                <input type="radio" name="goods[isalert]" value="1" {if $item['isalert']==1 || $item['isalert']==0}checked="checked"{/if}> 关闭
            </label>
            <label class="radio radio-inline">
                <input type="radio" name="goods[isalert]" value="2" {if $item['isalert']==2}checked="checked"{/if}>开启(真实用户参与过多的情况下，会根据限制随机发送200个通知)
            </label>
        </div>
    </div>    
    <div class="form-group">
        <label class="col-lg control-label">自动发货</label>
        <div class="col-xs-12 col-sm-3 input-group" style="float: left;margin-left: 15px;">
            <input type="text" name="goods[automatic]" class="form-control" value="{$item['automatic']}">
            <span class="input-group-addon">个</span>
        </div>  
        <div class="col-xs-12 col-sm-8" style="width: 33.3%;">
            <label class="radio radio-inline">
                <input type="radio" name="goods[select_automatic]" value="1" {if $item['select_automatic']==1 || empty($item['select_automatic'])}checked="checked"{/if}> 关闭
            </label>
            <label class="radio radio-inline">
                <input type="radio" name="goods[select_automatic]" value="2" {if $item['select_automatic']==2}checked="checked"{/if}>积分
            </label>
            <label class="radio radio-inline">
                <input type="radio" name="goods[select_automatic]" value="3" {if $item['select_automatic']==3}checked="checked"{/if}>夺宝币
            </label>
        </div>
    </div>
    <div class="form-group">
        <label class="col-lg control-label">商品总期数</label>
        <div class="col-xs-12 col-sm-4">
            <div class="input-group">
                <input type="text" name="goods[maxperiods]" class="form-control" value="{$item['maxperiods']}" >
                <span class="input-group-addon">期</span>
            </div>
        </div>
    </div>
    <div class="form-group">
        <label class="col-lg control-label">揭晓分钟数</label>
        <div class="col-xs-12 col-sm-8">
            <div class="input-group">
                <input type="text" name="goods[jiexiaotime]" class="form-control" value="{$item['jiexiaotime']}" >
                <span class="help-block">中奖后倒计时分钟数（整数）</span>
            </div>
        </div>
    </div>
    <div class="form-group">
        <label class="col-lg control-label">商品中奖码(例1000001)</label>
        <div class="col-xs-12 col-sm-8">
            <input type="text" name="code" class="form-control" value="{$item['code']}" />
            <span class="help-block">第一次添加商品时，请勿填写，等添加购买以后再填（谨慎使用）</span>
        </div>
    </div>
    <div class="form-group-title" style="display: none;">一口价设置</div>
    <div class="form-group" style="display: none;">
        <label class="col-lg control-label">是否开启全价购买</label>
        <div class="col-xs-12 col-sm-8" style="width: 70%;">
            <label class="radio radio-inline">
                <input type="radio" name="goods[isalone]" value="0" {if $item['isalone']==0 || $item['isalone']==0}checked="checked"{/if}> 关闭
            </label>
            <label class="radio radio-inline">
                <input type="radio" name="goods[isalone]" value="1" {if $item['isalone']==1}checked="checked"{/if}>开启
            </label>
        </div>
    </div>
    <div class="form-group" style="display: none;">
        <label class="col-lg control-label">直接购买价格</label>
        <div class="col-xs-12 col-sm-8">
            <div class="input-group">
                <input type="text" placeholder="请输入直接购买价格" name="goods[aloneprice]" class="form-control" value="{$item['aloneprice']}" >
                <span class="input-group-addon">元</span>
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="col-xs-12 col-sm-9 col-md-10 col-lg-10 col-sm-offset-3 col-md-offset-2 col-lg-offset-2">
            <input type="hidden" name="id" value="{$item['id']}" />
            <input type="hidden" name="periods" value="{$item['periods']}" />
            <input type="hidden" name="maxcode" value="{$item['price']}" />
            <input name="submit" type="submit" value="提交" class="btn btn-primary" />
        </div>
    </div>
</form>
</div>
<script type="text/javascript">
    $('form').submit(function(){
        var re = /^[1-9]+[0-9]*]*$/; 
        if(!re.test($('input[name="goods[init_money]"]').val())){
            $('form').attr('stop',1),tip.msgbox.err('几元专区必须是正整数.');
            return false;
        }
        if($('input[name="goods[title]"]').val() == ''){
            $('form').attr('stop',1),tip.msgbox.err('请填写商品名称.');
            return false;
        }
        if($('input[name="goods[picarr]"]').val() == ''){
            $('form').attr('stop',1),tip.msgbox.err('请上传商品图片.');
            return false;
        }
        if(!re.test($('input[name="goods[price]"]').val()/$('input[name="goods[init_money]"]').val())){
            $('form').attr('stop',1),tip.msgbox.err('商品价格必须是'+$('input[name="goods[init_money]"]').val()+'的整数倍');
            return false;
        }
        var maxperiods = parseFloat($('input[name="goods[maxperiods]"]').val());
        if(isNaN(maxperiods)){
            $('form').attr('stop',1),tip.msgbox.err('请填写商品期数.');
            return false;
        }
        return true;
    });
</script>
{include file='_footer'}